﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyThietBi.DAL.Models;

namespace QuanLyThietBi.DAL
{
    public class PhongBanDAO
    {
        public List<PHONGBAN> GetAllPhongBan() 
        {
            List<PHONGBAN> dsPhongBan = null;
            try
            {
                using (var en = new QuanLyThietBiEntities())
                {
                    var ds = from tb in en.PHONGBANs
                             select tb;
                    if (ds != null)
                    {
                        dsPhongBan = ds.ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dsPhongBan;
        }

        //lấy ra object phòng ban theo phòng ban ID
        public PHONGBAN GetPhongBanById(int phongbanId) 
        {
            PHONGBAN pb = null;
            try
            {
                using (var en = new QuanLyThietBiEntities())
                {
                    var ds = from tb in en.PHONGBANs
                             where tb.id == phongbanId
                             select tb;
                    if (ds != null)
                    {
                        pb = ds.FirstOrDefault();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return pb;
        }    

        public string GetTenPhongBanById(int phongbanId)
        {
            string phongban = string.Empty;
            try
            {
                using (var en = new QuanLyThietBiEntities())
                {
                    var ds = from ltb in en.PHONGBANs
                             where ltb.id == phongbanId
                             select ltb;
                    if (ds != null)
                    {
                        phongban = ds.FirstOrDefault().phong_ban;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return phongban;
        }
    }
}
